package com.qmx.qmxapp.fragment;


import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.qmx.qmxapp.R;
import com.qmx.qmxapp.adapter.ItemClickAdapter;
import com.qmx.qmxapp.base.BaseFragment;
import com.qmx.qmxapp.bean.ClickEntity;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class HandsupFragment extends BaseFragment {
    private View fragment_folder;
    private RecyclerView mRecyclerView;
    private ItemClickAdapter adapter;
    private HandsupMessage handsupMessage;


    public HandsupFragment() {
        // Required empty public constructor
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        handsupMessage = (HandsupMessage) activity;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        fragment_folder = inflater.inflate(R.layout.fragment_handsup, container, false);
        mRecyclerView = (RecyclerView) fragment_folder.findViewById(R.id.recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        initAdapter();
        adapter.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                Toast.makeText(getActivity(), "onItemChildClick" + position, Toast.LENGTH_SHORT).show();
                handsupMessage.handsupMessage("举手" + position);
            }
        });
        return fragment_folder;

    }

    private void initAdapter() {
        List<ClickEntity> data = new ArrayList<>();
        data.add(new ClickEntity(ClickEntity.CLICK_ITEM_VIEW));
        adapter = new ItemClickAdapter(data);
        adapter.openLoadAnimation();
        mRecyclerView.setAdapter(adapter);
    }


    public interface HandsupMessage {
        void handsupMessage(String msg);
    }

}
